package lesson01;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @Auther: xiaofei
 * @Date: 2021/6/28 - 06 - 28 - 16:02
 * @Description: lesson01
 * @version: 1.0
 */
public class UdpClientDemo01 {
    //这是一个main方法，是程序的入口：
    public static void main(String[] args) throws Exception {
        // 1.建立一个socket
        DatagramSocket socket = new DatagramSocket();
        // 2.建个包
        String msg = "你好啊，服务器！";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);

        // 3.发个包
        socket.send(packet);

        // 4.关闭流
        socket.close();
    }
}
